<template>
  <div style="height:480px;width:100%;position:relative;">
      <div class="pagetop">
          <table style="font-size:12px;white-space: nowrap;max-width: 1170px;">
              <tr>
                  <td align="right" style="width: 60px">上报人</td>
                  <td style="width: 100px">
                      <rm-ddl-common datatype="reportuser" dataname="用户" v-model="chkuser" width="100px" @change="ChkUserChange"></rm-ddl-common>
                  </td>
                  <td align="right" style="width: 60px">审核状态</td>
                  <td style="width: 100px">
                      <el-radio-group v-model="rechkflag" @change="LoadSave">
                          <el-radio :label="'1'">全部</el-radio>
                          <el-radio :label="'9'">已审</el-radio>
                          <el-radio :label="'0'">未审</el-radio>
                      </el-radio-group>
                  </td>
                  <td align="right" style="width: 60px">病人类型</td>
                  <td style="width: 100px">
                      <rm-ddl-common datatype="seccode" dataname="病人类型" kindno="PT" v-model="ptype" width="100px" @change="PtChange"></rm-ddl-common>
                  </td>
              </tr>
              <tr>
                  <td align="right">标本号</td>
                  <td>
                      <el-input v-model="sampleno" placeholder="支持1,2,5-8等格式" style="width:100px" @keyup.enter.native="InitPage()"></el-input>
                  </td>
                  <!-- <td align="right">打印状态</td>
                  <td>
                      <el-radio-group v-model="printflag" @change="LoadSave">
                          <el-radio :label="'1'">全部</el-radio>
                          <el-radio :label="'9'">已打印</el-radio>
                          <el-radio :label="'0'">未打印</el-radio>
                      </el-radio-group>
                  </td> -->
              </tr>
          </table>
          <!-- <div class="search-title">上报人</div>
          <rm-ddl-common datatype="reportuser" dataname="用户" v-model="chkuser" width="100px" @change="ChkUserChange"></rm-ddl-common>
          <div class="search-title">病人类型</div>
          <rm-ddl-common datatype="seccode" dataname="病人类型" kindno="PT" v-model="ptype" width="120px" @change="PtChange"></rm-ddl-common>
          <div class="search-title">审核状态</div>
          <el-radio-group v-model="rechkflag" @change="LoadSave">
              <el-radio :label="'1'">全部</el-radio>
              <el-radio :label="'9'">已审</el-radio>
              <el-radio :label="'0'">未审</el-radio>
          </el-radio-group>
          <div class="search-title">打印状态</div>
          <el-radio-group v-model="printflag" @change="LoadSave">
              <el-radio :label="'1'">全部</el-radio>
              <el-radio :label="'9'">已打印</el-radio>
              <el-radio :label="'0'">未打印</el-radio>
          </el-radio-group>
          <div class="search-title-next">标本号</div>-->
          <div class="top-deal">
              <el-button @click="btnPrint()" type="primary" icon="el-icon-printer">打印</el-button>
              <el-button @click.native="RptStyleSetting" class="el-icon-edit-outline">打印样式设计</el-button>
              <el-button style="float: right; " @click="btnCancel" icon="el-icon-close">取消</el-button>
          </div>
      </div>
      <div class="pagecenter">
          <div class="middle-center">
              <vxe-table :data.sync="tableData" :loading="loading" :keyboard-config="keyConfig" :select-config="selectConfig" :sort-config="{trigger: 'cell'}" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row class="mytablestyle" highlight-hover-column ref="xTable" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe>
                  <vxe-table-column type="selection" width="40" align="center"></vxe-table-column>
                  <vxe-table-column align="center" field="seq" title="序号" width="40"></vxe-table-column>
                  <vxe-table-column field="sampleno" align="center" title="标本号" width="50" sortable>
                  </vxe-table-column>
                  <vxe-table-column align="center" field="pat_typename" title="类型" width="50" sortable></vxe-table-column>
                  <vxe-table-column field="pat_no" title="住院号" width="100" sortable> </vxe-table-column>
                  <vxe-table-column align="center" field="pat_name" title="病人姓名" width="80" sortable></vxe-table-column>
                  <vxe-table-column field="req_wardname" title="病区" width="140" sortable></vxe-table-column>
                  <vxe-table-column align="center" field="req_bedno" title="床号" width="45" sortable></vxe-table-column>
                  <vxe-table-column field="rpt_itemname" title="项目" width="150" sortable> </vxe-table-column>
                  <vxe-table-column field="result_str" title="结果" width="80" sortable></vxe-table-column>
                  <vxe-table-column align="center" field="deptname" title="申请科室" width="80" sortable></vxe-table-column>
                  <vxe-table-column align="center" field="docname" title="申请医生" width="80" sortable></vxe-table-column>
                  <vxe-table-column align="center" field="alertmanname" title="危急值发送人" width="80" sortable></vxe-table-column>
                  <vxe-table-column align="center" field="hischeckmanname" title="临床确认人" width="80" sortable></vxe-table-column>
              </vxe-table>
          </div>
      </div>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  props: {
      rptunitid: { type: Number }
  },
  data() {
      return {
          rechkflag: "1",
          printflag: "1",
          ptype: "3",
          loading: false,
          keyConfig: {
              isDel: true,
              isTab: true,
              isEdit: true,
              isArrow: true
          },
          keyLocalConfig: {
              isArrow: true
          },
          selectConfig: { tigger: "row", checkAll: true },
          tableData: [],
          userno: this.$tool.getSession(this.$tool.loginuserno),
          chkuser: "",
          sampleno: ""
      };
  },
  created() {},
  watch: {},
  computed: {},
  mounted() {
      let modOption = localStorage.getItem("AlertResultList");
      let tempOption = JSON.parse(modOption);
      if (modOption) {
          this.rechkflag = tempOption.rechkflag;
          this.ptype = tempOption.ptype;
      }
      this.$nextTick(() => {
          this.InitPage();
      });
  },
  updated() {},
  methods: {
      LoadSave() {
          let jsondata = { rechkflag: this.rechkflag, ptype: this.ptype, printflag: this.printflag, sampleno: this.sampleno };
          let modListJson = JSON.stringify(jsondata);
          localStorage.setItem("AlertResultList", modListJson);
          this.$nextTick(() => {
              this.InitPage();
          });
      },
      InitPage() {
          this.loading = true;
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS310",
                  method: "post",
                  data: {
                      action: "alertresult",
                      rptunitid: this.rptunitid,
                      rechkflag: this.rechkflag,
                      pat_type: this.ptype,
                      chkuser: this.chkuser,
                      sampleno: this.sampleno,
                      printflag: this.printflag
                  }
              })
              .then(res => {
                  console.log("res", res);
                  this.tableData = res.Data;
                  this.loading = false;
              })
              .catch(err => {
                  this.loading = false;
              });
      },

      btnCancel() {
          this.$emit("cancel");
      },
      btnPrint() {
          var data = this.$refs.xTable.getSelectRecords();
          var printdata = [];
          for(let i = 0;i < this.$refs.xTable.afterFullData.length;i++)
          {
              let nowrow = this.$refs.xTable.afterFullData[i];
              //2021-03-03 by liang 今日危急值修正打印数据中同一病人多个危急值项目结果出现相同
              //let findrow = data.find(item => item.sampleno == nowrow.sampleno && item.rptunitid == nowrow.rptunitid);
              let findrow = data.find(item => item.sampleno == nowrow.sampleno && item.rptunitid == nowrow.rptunitid && item.rpt_itemname == nowrow.rpt_itemname);
              if(findrow) printdata.push(findrow);
          }
          if (data.length > 0) {
              const rload = this.$pub.openLoading(this, "正在打印，请稍候……");
              let column = this.$refs.xTable.getTableColumn().tableColumn;
              let str = JSON.stringify(this.$pub.InitColumn(column));
              str += "\r";
              str += JSON.stringify(printdata);
              let sql = btoa(encodeURIComponent(str));
              jsObj.PrintCustomJsonReport("5027", sql, this.userno, "危急值清单样式", "");
              rload.close();
          } else {
              this.$alert("无可打印的数据");
          }
      },
      PrintUpdate(data) {
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS310",
                  method: "post",
                  data: {
                      action: "alertresultprint",
                      urec: data
                  }
              })
              .then(res => {
                  if (res.hasOwnProperty("errcode")) {
                  }
              })
              .catch(err => {
                  this.loading = false;
              });
      },
      RptStyleSetting() {
          var data = this.$refs.xTable.getSelectRecords();
          if (data.length > 0) {
              const rload = this.$pub.openLoading(this, "正在打开报表设计器，请稍候……");
              let column = this.$refs.xTable.getTableColumn().tableColumn;
              let str = JSON.stringify(this.$pub.InitColumn(column));
              str += "\r";
              str += JSON.stringify(data);
              let sql = btoa(encodeURIComponent(str));
              jsObj.SetCustomJsonPrintConfig("5027", sql, this.userno, "危急值清单样式");
              rload.close();
          } else {
              this.$alert("无可打印的数据！");
          }
      },
      PtChange(code, name) {
          this.LoadSave();
          this.InitPage();
      },
      ChkUserChange(code) {
          this.chkuser = code;
          this.InitPage();
      }
  }
};
</script>

<style scoped>
.pagetop {
  width: 100%;
  height: 70px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}
.top-deal {
  right: 5px;
  position: absolute;
  top: 40px;
  display: flex;
  align-items: center;
}
.pagecenter {
  position: absolute;
  top: 75px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 400px;
  left: 0px;
  right: 0px;
  overflow: auto;
}
.search-title {
  margin: 0 3px 0 8px;
  font-size: 12px;
}
.search-title-next {
  left: 5px;
  position: absolute;
  top: 40px;
  display: flex;
  align-items: center;
}
/deep/.Update {
  color: blue;
}
</style>